<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['tdm:TdmSanYiLiaoQiXie:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tdm:TdmSanYiLiaoQiXie:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tdm:TdmSanYiLiaoQiXie:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tdm:TdmSanYiLiaoQiXie:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="TdmSanYiLiaoQiXieList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="yiLeiBie" label="类型" align="center" :formatter="Formatter" />
      <el-table-column label="一级产品类别" align="center" prop="yiJiChanPin" />
      <el-table-column label="二级产品类别" align="center" prop="erJiChanPin" />
<!--      <el-table-column label="审核" align="center" prop="shenHe" />-->
      <el-table-column label="处理状态" align="center" key="shenHe" id="colourType">
        <template slot-scope="scope">
          <el-button type="success">
            <span @click="getValue(scope.row)" v-if="scope.row.shenHe == 0 ">未审核</span>
            <span @click="getValue(scope.row)" v-if="scope.row.shenHe == 1 ">已初审</span>
            <span @click="getValue(scope.row)" v-if="scope.row.shenHe == 2 ">已终审</span>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tdm:TdmSanYiLiaoQiXie:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tdm:TdmSanYiLiaoQiXie:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改ID-07 三类医疗器械对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="药物类型" prop="typeId">
          <el-checkbox-group v-model="form.typeId" @change="handleSelectionChange">
            <el-checkbox v-for="date in typeIdArr" :label="date.key" :key="date.key">{{date.label}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="类型" >
          <el-select v-model="form.yiLeiBie" @change="leiXing" placeholder="请选择" style="width: 100%;">
            <el-option v-for="item in stateArr" :key="item.value" :label="item.label" :value="parseInt(item.value)">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="一级产品类别" prop="yiJiChanPin">
          <el-input v-model="form.yiJiChanPin" placeholder="请输入一级产品类别" />
        </el-form-item>
        <el-form-item label="二级产品类别" prop="erJiChanPin">
          <el-input v-model="form.erJiChanPin" placeholder="请输入二级产品类别" />
        </el-form-item>
        <el-form-item label="产品描述" prop="chanPinMiaoShu">
          <el-input v-model="form.chanPinMiaoShu" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预期用途" prop="yuQiYongTu">
          <el-input v-model="form.yuQiYongTu" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="品名举例" prop="pinMingJuLi">
          <el-input v-model="form.pinMingJuLi" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTdmSanYiLiaoQiXie, getTdmSanYiLiaoQiXie, delTdmSanYiLiaoQiXie, addTdmSanYiLiaoQiXie, updateTdmSanYiLiaoQiXie,to_examine } from "@/api/tdm/TdmSanYiLiaoQiXie";

export default {
  name: "TdmSanYiLiaoQiXie",
  data() {
    return {
      stateArr: [
        {value: '1',label: '有源手术器械'},
        {value: '2',label: '无源手术器械'},
        {value: '3',label: '神经和心血管手术器械'},
        {value: '4',label: '骨科手术器械'},
        {value: '5',label: '放射治疗器械'},
        {value: '6',label: '医用成像器械'},
        {value: '7',label: '医用诊察和监护器械'},
        {value: '8',label: '呼吸、麻醉和急救器械'},
        {value: '9',label: '物理治疗器械'},
        {value: '10',label: '输血、透析和体外循环器械'},
        {value: '11',label: '医疗器械消毒灭菌器械'},
        {value: '12',label: '有源植入器械'},
        {value: '13',label: '无源植入器械'},
        {value: '14',label: '注射、护理和防护器械'},
        {value: '15',label: '患者承载器械'},
        {value: '16',label: '眼科器械'},
        {value: '17',label: '口腔科器械'},
        {value: '18',label: '妇产科、辅助生殖和避孕器械'},
        {value: '19',label: '医用康复器械'},
        {value: '20',label: '中医器械'},
        {value: '21',label: '医用软件'},
        {value: '22',label: '临床检验器械'},],
      typeIdArr: [
        {key: "10", label: "通用",},
        {key: "1001", label: "复杂体系",},
        {key: "1002", label: "肿瘤药物",},
        {key: "100101", label: "过敏物",}],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // ID-07 三类医疗器械表格数据
      TdmSanYiLiaoQiXieList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        yiLeiBie: null,
        yiJiChanPin: null,
        erJiChanPin: null,
        chanPinMiaoShu: null,
        yuQiYongTu: null,
        pinMingJuLi: null,
        typeId: [],
        shenHe: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // yiLeiBie: [
        //   { required: true, message: "1: 有源手术器械 2: 无源手术器械 3: 神经和心血管手术器械 4:骨科手术器械 5: 放射治疗器械不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询ID-07 三类医疗器械列表 */
    getList() {
      this.loading = true;
      listTdmSanYiLiaoQiXie(this.queryParams).then(response => {
        this.TdmSanYiLiaoQiXieList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        yiLeiBie: 1,
        yiJiChanPin: null,
        erJiChanPin: null,
        chanPinMiaoShu: null,
        yuQiYongTu: null,
        pinMingJuLi: null,
        createTime: null,
        updateTime: null,
        typeId: ['10'],
        shenHe: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    Formatter(row, column){
      var yiLeiBie = row.yiLeiBie;
      if(yiLeiBie == 1) return "有源手术器械"
      else if(yiLeiBie == 2) return "无源手术器械"
      else if(yiLeiBie == 3) return "神经和心血管手术器械"
      else if(yiLeiBie == 4) return "骨科手术器械"
      else if(yiLeiBie == 5) return "放射治疗器械"
      else if(yiLeiBie == 6) return "医用成像器械"
      else if(yiLeiBie == 7) return "医用诊察和监护器械"
      else if(yiLeiBie == 8) return "呼吸、麻醉和急救器械"
      else if(yiLeiBie == 9) return "物理治疗器械"
      else if(yiLeiBie == 10) return "输血、透析和体外循环器械"
      else if(yiLeiBie == 11) return "医疗器械消毒灭菌器械"
      else if(yiLeiBie == 12) return "有源植入器械"
      else if(yiLeiBie == 13) return "无源植入器械"
      else if(yiLeiBie == 14) return "注射、护理和防护器械"
      else if(yiLeiBie == 15) return "患者承载器械"
      else if(yiLeiBie == 16) return "眼科器械"
      else if(yiLeiBie == 17) return "口腔科器械"
      else if(yiLeiBie == 18) return "妇产科、辅助生殖和避孕器械"
      else if(yiLeiBie == 19) return "医用康复器械"
      else if(yiLeiBie == 20) return "中医器械"
      else if(yiLeiBie == 21) return "医用软件"
      else if(yiLeiBie == 22) return "临床检验器械"
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加  三类医疗器械";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTdmSanYiLiaoQiXie(id).then(response => {
        this.form = response.data;
        this.form.typeId = this.form.typeId.split(",");
        this.open = true;
        this.title = "修改  三类医疗器械";
      });
    },
    getValue: function(row) {
      // 修改值为已初审
      if (row.shenHe == 0){
        to_examine(row.id,1,'tdm_san_yi_liao_qi_xie');
        // 修改值为已终审
      } else if (row.shenHe == 1){
        to_examine(row.id,2,'tdm_san_yi_liao_qi_xie');
      } else if (row.shenHe == 2){
        this.$modal.msgSuccess("已终审！");
      }
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.typeId = this.form.typeId.join(",");
          if (this.form.id != null) {
            updateTdmSanYiLiaoQiXie(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTdmSanYiLiaoQiXie(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除  三类医疗器械编号为"' + ids + '"的数据项？').then(function() {
        return delTdmSanYiLiaoQiXie(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('tdm/TdmSanYiLiaoQiXie/export', {
        ...this.queryParams
      }, `TdmSanYiLiaoQiXie_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
